package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 分页条件查询
     *
     * @param empQueryParam
     * @return
     */
    Page<Emp> pageQuery(EmpQueryParam empQueryParam);


    /**
     * 添加员工
     *
     * @param emp
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    /**
     * 批量删除员工
     *
     * @param ids
     */
    void deleteByIds(List<Integer> ids);


    /**
     * 根据id查询员工基本信息
     *
     * @param id
     * @return
     */
    @Select("select * from emp where id = #{id}")
    Emp selectById(Integer id);


    /**
     * 根据员工id查询员工所有信息（emp和emp_expr表联查）
     *
     * @param id
     * @return
     */
    Emp getById(Integer id);

    /**
     * 更新员工信息
     *
     * @param emp
     * @return
     */
    void updateById(Emp emp);

    /**
     * 查询全部员工
     *
     * @return
     */
    @Select("select * from emp where job = 1 order by update_time desc ")
    List<Emp> selectAll();


    /**
     * 员工登录（ 通过用户名与密码查询用户信息）
     *
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectUsernameAndPassword(Emp emp);

    @Select("select distinct image from emp")
    List<String> selectAllImage();
}
